
fn main() {
    // 匹配一个字面值
    let x = 1;
    match x {
        1 => println!("one"),
        2 => println!("two"),
        3 => println!("three"),
        _ => println!("anything"),
    }
    // 匹配重命名变量
    let x = Some(5);
    let y = 10;
    match x {
        Some(50) => println!("Got 50"),
        Some(y) => println!("Matched, y = {:?}", y), // 此处的y不是let y = 10;中的y
        _ => println!("Default case, x = {:?}", x),
    };
    println!("at the end: x = {:?}, y = {:?}", x, y); // 此处的y是let y = 10;中的y

    // 多个模式
    let x = 1;
    match x {
        1 | 2 => println!("1 or 2"), // 标识的是或，匹配1或者2
        3 => println!("three"),
        _ => println!("anything"),
    }

    // 通过 .. 来进行匹配
    let x = 2;
    match x {
        1..=5 => println!("1 through 5"),
        _ => println!("something else"),
    }

    let x = 'x';
    match x {
        'a'..='j' => println!("early ASCII letter 1"),
        'k'..='z' => println!("late ASCII letter 2"),
        _ => println!("something else"),
    }
}
